const app = getApp()
import {urls} from '../../../utils/urls'
let _this;
Page({
  data: {
    list:[],
    load:false
  },
  del(e){
    let index = e.currentTarget.dataset.index
    wx.showModal({
      title: '提示',
      content: '删除后该数据将无法恢复，是否继续?',
      success(res){
        if(res.confirm){
          wx.showLoading({
            title: '删除中',
            task:true
          })
          app.http('DELETE',urls.addr,{id:_this.data.addr_list[index].id},
          function(res){
            wx.hideLoading()
            if(res.code == 100){
              wx.showToast({
                title: '删除成功',
                task:true
              })
              _this.getList()
            }else{
              wx.showToast({
                title: '删除失败',
                icon: 'none'
              })
            }
          })
        }
      }
    })
  },
  edit(e){
    wx.navigateTo({
      url: '/pages/mine/addressinfo/addressinfo?data='+JSON.stringify(this.data.addr_list[e.currentTarget.dataset.index]),
    })
  },
  onLoad: function () {
    _this = this
    _this.getList()
  },
  getList(){
    this.setData({
      load:true
    })
    app.http('GET',urls.addr,{type: 1,user:wx.getStorageSync('user').id},
    function(res){
      if(res.code == 100){
        _this.setData({
          addr_list:res.results,
          load:false
        })
      }
    })
  },
  onShow: function (){
    this.setData({
      defId:wx.getStorageSync("user").default_address
    })
  },
  onPullDownRefresh() {
	_this.getList()
  },
})